package qsoft.omanga.common.utils;

import java.util.Calendar;
import java.util.List;

/***
 * 
 * @author sontt
 * 
 */
public class StringUlti {
    /**
     * 
     */
    private static final StringUlti STRING_ULTI = new StringUlti();

    /**
     * @return StringUlti
     */
    public static StringUlti getInstance() {
        return STRING_ULTI;
    }

    /**
     * 
     */
    public static final String SEPARATE_COMMA = ", ";

    /**
     * 
     * @param hourOfDay
     *            int
     * @param minute
     *            int
     * @param ampm
     *            String
     * @return String formatTime
     */
    public String formatTime(int hourOfDay, int minute, String ampm) {
        return pad(hourOfDay) + ":" + pad(minute) + " " + ampm;
    }

    /**
     * 
     * @param dayOfWeek
     *            int
     * @param dayOfMonth
     *            int
     * @param month
     *            int
     * @param year
     *            int
     * @return String formatDate
     */
    public String formatDate(int dayOfWeek, int dayOfMonth, int month, int year) {
        return formatDayOfWeek(dayOfWeek) + ", " + dayOfMonth + "/"
                + (month + 1) + "/" + year;
    }

    /**
     * 
     * @param listDay
     *            Vector<Integer>
     * @return String
     */
    public String getListDays(List<Integer> listDay) {
        String list = "";
        if (listDay.size() == 7) {
            list = "Every Day";
        } else if (listDay.size() == 2 && listDay.get(0) == Calendar.SATURDAY
                && listDay.get(1) == Calendar.SUNDAY) {
            list = "Weekend";
        } else {
            boolean flag = true;
            for (int i = 0; i < listDay.size(); i++) {
                if (listDay.size() == 5
                        && (listDay.get(i) == Calendar.SATURDAY || listDay
                                .get(i) == Calendar.SUNDAY)) {
                    flag = false;
                    break;
                } else {
                    if (i == listDay.size() - 1) {
                        list += formatDayOfWeek(listDay.get(i));
                    } else {
                        list += formatDayOfWeek(listDay.get(i))
                                + SEPARATE_COMMA;
                    }
                }
            }
            if (flag) {
                list = "Weekdays";
            }
        }
        return list;
    }

    /**
     * 
     * @param ampm
     *            int
     * @return String getAMPM
     */
    public String getAMPM(int ampm) {
        if (ampm == 0) {
            return "AM";
        } else {
            return "PM";
        }
    }

    /**
     * 
     * @param hourOfDay
     *            int
     * @return int formatHour
     */
    public int formatHour(int hourOfDay) {
        int hour = hourOfDay;
        if (hourOfDay > 12) {
            hour = hourOfDay - 12;
        }
        return hour;
    }

    /**
     * 
     * @param c
     *            int
     * @return String pad
     */
    public String pad(int c) {
        if (c >= 10) {
            return Integer.toString(c);
        } else {
            return "0" + Integer.toString(c);
        }

    }

    /**
     * 
     * @param c
     *            int
     * @return String formatDayOfWeek
     */
    public String formatDayOfWeek(int c) {
        String day = "";
        switch (c) {
        case Calendar.MONDAY:
            day = "Mon";
            break;
        case Calendar.TUESDAY:
            day = "Tue";
            break;
        case Calendar.WEDNESDAY:
            day = "Wed";
            break;
        case Calendar.THURSDAY:
            day = "Thu";
            break;
        case Calendar.FRIDAY:
            day = "Fri";
            break;
        case Calendar.SATURDAY:
            day = "Sat";
            break;
        case Calendar.SUNDAY:
            day = "Sun";
            break;
        }
        return day;
    }

}
